<?php
/**
 * Programs is an instance of CActiveRecord (sytem.db.ar). 
 *
 * CActiveRecord is the base class for classes representing relational data. 
 *
 * Eduow :  International system for education (http://www.eduow.com)
 * Copyright 2010, Nikolay Stoitsev
 *
 * Licensed under GNU General Public License version 2
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright 2010
 * @link          http://eduow.com Eduow Project
 * @package       eduow
 * @subpackage    application.models
 * @inheritance   class Programs >> CActiveRecord >> CModel >> CComponent
 * @implements    ArrayAccess, Traversable, IteratorAggregate
 * @since         Eduow v 0.0.4
 * @license       http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License version 2
 */

class Programs extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'programs':
	 * @var integer $id
	 * @var string $title
	 * @var integer $author
	 * @var string $code
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__){
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName(){
		return 'programs';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules(){
		return array(
			array('title, author, code, category', 'required'),
			array('author', 'numerical', 'integerOnly'=>true),
			array('title', 'length', 'max'=>100),
			array('id, title, author, code', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels(){
		return array(
			'id' => Yii::t('yii','Id'),
			'title' => Yii::t('yii','Title'),
			'author' => Yii::t('yii','Author'),
			'code' => Yii::t('yii','Code'),
			'category'=>Yii::t('yii','Category')
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search(){
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('title',$this->title,true);

		$criteria->compare('author',$this->author);

		$criteria->compare('code',$this->code,true);

		return new CActiveDataProvider('Programs', array(
			'criteria'=>$criteria,
		));
	}
}
